<!--
 * @description  : 证件-字典类型选择组件
 * @descriptionDetail: 证件-字典类型选择组件
 * @copyright    : 浙江烟草
 * @author       : sy
 * @create       : 2022-09-03 15:29:13
-->
<template>
  <view class="page">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar :isWhite="true" title="选择" backText="返回">
      <view class="navbar-right" @click="confirmBack">
        确定
      </view>
    </theme-navbar>
    <!-- #endif -->
		<!-- #ifdef H5-WECHAT || H5-EMP -->
		<fab-button :content="fContent" @fabtrigger="fabtrigger" />
		<!-- #endif -->
    <view class="content">
      <u-checkbox
        :shape="isRadio?'circle':'square'"
        :name="item.bcbCode"
        :label-disabled="true"
        :disabled="item.disabled"
        v-for="(item, index) in dicList"
        :key="index"
        v-model="item.checked"
        @change="checkboxChange(index,$event)"
      >
        {{ item.bcbName }}
      </u-checkbox>
    </view>
  </view>
</template>

<script>
	import common from "@/components/commonMixins.js";
	import commonService from "@/service/common/common.service.js";
	import fabButton from '@/components/uni-fab.vue';

	export default {
		components: {
			fabButton
		},
		mixins: [common, ],
		data() {
			return {
				tabTitle: '',
				selectIndex: [], // 选中的index
				selectResult: [], // 选中的数据
				isRadio: false, // 是否单选
				value: '',
				dicList: [],
				dictType: '',
				licenseCode: '',
				fContent: [{
					iconPath: require('@/static/confirm.png'),
					selectedIconPath: require('@/static/confirm.png'),
					text: '确定',
					active: false,
				}],
			};
		},
		mounted() {
			this.setRightBtns();
			this.getDicData();
		},
		onLoad(options) {
			this.dictType = options.type;
			this.licenseCode = options.licenseBasis ? options.licenseBasis : '';
		},
		methods: {
			// 设置右侧标题
			setRightBtns() {
				// #ifdef H5-DINGDING
				this.$deviceApi.setRight("确定", () => {
					this.confirmBack();
					this.setRightBtns();
				}, true, true);
				// #endif
			},
			fabtrigger(btn) {
				if (btn.index == 0) {
					this.confirmBack();
				}
			},
			getDicData() {
				let self = this;
				commonService.bscCodesMap(this.dictType).then(dicData => {
					let dicLists = dicData.bean[this.dictType];
					dicLists.forEach(item => {
						item['checked'] = self.licenseCode.includes(item.bcbCode);
					});
					this.dicList = dicLists;
				});
			},
			// 点击确定返回列表页
			confirmBack() {
				console.log(this.selectResult)
				let self = this;
				if (this.dicList.length > 0) {
					for (let item of this.dicList) {
						item.checked && this.selectResult.push(item);
					}
				}

				if (this.selectResult.length > 0) {
					self.backPrev({
						paramKey: "backList",
						param: {
							type: 'dic',
							arry: this.selectResult,
						},
					});
				} else {
					this.$api.toast('请选择添加项');
				}

			},
			// 选中某个复选框时，由checkbox时触发
			checkboxChange(index, e) {
				this.dicList[index].checked = e.value;
			},
		},
	};
</script>
<style lang="scss" scoped>
	@import "style/certificate/common.scss";

	.u-check-box {
		width: 100%;
		padding: 10px;
	}

	/deep/.u-checkbox {
		width: 100%;
		padding-bottom: 10px;
	}

	/deep/.u-checkbox__label {
		line-height: 28px;
	}
</style>
